package com.lqk.shardingjdbcproj.controller;

import com.lqk.shardingjdbcproj.entity.Udict;
import com.lqk.shardingjdbcproj.entity.User;
import com.lqk.shardingjdbcproj.entity.response.ReturnReponse;
import com.lqk.shardingjdbcproj.enums.ResponseEnum;
import com.lqk.shardingjdbcproj.service.UdictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
public class UdictController {

    @Autowired
    private UdictService udictService;

    // 水平分库
    @RequestMapping(value="/addUdict",method = RequestMethod.POST)
    public ReturnReponse addUdict(@RequestBody Udict udict){
        int i = udictService.insertStatus(udict);
        if (i>0){
            return ReturnReponse.success(ResponseEnum.CODE_200.getCode(), ResponseEnum.CODE_200.getMessage());
        }else {
            return ReturnReponse.fail(ResponseEnum.CODE_400.getCode(), ResponseEnum.CODE_400.getMessage());
        }
    }

    @RequestMapping(value="/getUdict",method = RequestMethod.POST)
    public ReturnReponse getUdict(@RequestParam long udictId){
        Udict udict = udictService.selectOne(udictId);
        return ReturnReponse.success(ResponseEnum.CODE_200.getCode(), ResponseEnum.CODE_200.getMessage(),udict);
    }

    @RequestMapping(value="/deleteUdict",method = RequestMethod.POST)
    public ReturnReponse deleteUdict(@RequestParam long udictId){
        int i = udictService.deleteById(udictId);
        if (i>0){
            return ReturnReponse.success(ResponseEnum.CODE_200.getCode(), ResponseEnum.CODE_200.getMessage(),true);
        }else {
            return ReturnReponse.fail(ResponseEnum.CODE_400.getCode(), ResponseEnum.CODE_400.getMessage(),false);
        }
    }
}
